/*
 * @Author: 深海有鱼 847094299@qq.com
 * @Date: 2025-04-03 22:52:00
 * @LastEditors: 深海有鱼 847094299@qq.com
 * @LastEditTime: 2025-08-24 19:45:53
 * @FilePath: \pure-admin-thin\src\api\adminProfitApi.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { http } from "@/utils/http";
import { useStreamDownload } from "@/utils/useStreamDownload";

/** 获取特定国家的收益统计数据 */
export const getCountryStats = (
  country: string,
  params?: {
    timeUnit?: string;
    startDate?: string;
    endDate?: string;
    page?: number;
    size?: number;
  }
) => {
  return http.request<any>(
    "get",
    `/api/admin/profits/countries/${country}/stats`,
    {
      params
    }
  );
};

/** 获取特定服务类型的收益统计数据 */
export const getServiceTypesStats = (
  serviceType: string,
  params?: {
    timeUnit?: string;
    startDate?: string;
    endDate?: string;
    page?: number;
    size?: number;
  }
) => {
  return http.request<any>(
    "get",
    `/api/admin/profits/service-types/${serviceType}/stats`,
    {
      params
    }
  );
};

/** 获取单个用户的收益统计数据 */
export const getUserProfitStats = (
  userId: number,
  params?: {
    type?: string;
    startDate?: string;
    endDate?: string;
    page?: number;
    size?: number;
  }
) => {
  return http.request<any>(
    "get",
    `/api/admin/profits/users/${userId}/stats`,
    {
      params
    }
  );
};

/** 获取用户收益排名 */
export const getUserProfitRanking = (params?: {
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
}) => {
  return http.request<any>("get", "/api/admin/profits/users/ranking", {
    params
  });
};

/** 获取系统总收益统计数据 */
export const getTotalProfitStats = (params?: {
  startDate?: string;
  endDate?: string;
}) => {
  return http.request<any>("get", "/api/admin/profits/summary", {
    params
  });
};

/** 获取按服务类型统计的收益数据 */
export const getServiceTypeProfitStats = (params?: {
  timeUnit?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
}) => {
  return http.request<any>("get", "/api/admin/profits/service-types/stats", {
    params
  });
};

/** 获取各用户的收益统计数据 */
export const getProfitUsersStats = (params?: {
  timeUnit?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
}) => {
  return http.request<any>("get", "/api/admin/profits/users/stats", {
    params
  });
};

/** 获取各服务类型的收益排名数据 */
export const getServiceProfitRanking = (params?: {
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
}) => {
  return http.request<any>("get", "/api/admin/profits/service-types/ranking", {
    params
  });
};

/** 获取各国家的收益统计数据 */
export const getProfitCountriesStats = (params?: {
  timeUnit?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
}) => {
  return http.request<any>("get", "/api/admin/profits/countries/stats", {
    params
  });
};
/** 获取各国家的收益排名数据 */
export const getCountriesProfitRanking = (params?: {
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
}) => {
  return http.request<any>("get", "/api/admin/profits/countries/ranking", {
    params
  });
};

/** 导出用户收益数据 */
export const exportUserProfit = (params?: {
  startDate?: string;
  endDate?: string;
}) => {
  const { download } = useStreamDownload();
  return download("/api/admin/profits/users/export", {
    method: "GET",
    params
  });
};

/** 导出用户收益数据 */
export const exportUserProfitSelected = (params?: {
  userIds?: string;
  startDate?: string;
  endDate?: string;
}) => {
  const { download } = useStreamDownload();
  return download("/api/admin/profits/users/export/selected", {
    method: "GET",
    params
  });
};
